libotutil: Add ot_keyfile_copy_group()
authorMatthew Barnes <mbarnes@redhat.com>
Wed, 3 Dec 2014 22:16:48 +0000 (17:16 -0500)
committerMatthew Barnes <mbarnes@redhat.com>
Mon, 8 Dec 2014 17:47:19 +0000 (12:47 -0500)
Copies all the keys of a group from one GKeyFile to another.

src/libotutil/ot-keyfile-utils.c
src/libotutil/ot-keyfile-utils.h

index 833a76f636acaceeb71ba0ce7aabcff3cfed6581..6a89357172c8b08b84aba0e48322da80c3d1caec 100644 (file)
@@ -91,3 +91,35 @@ ot_keyfile_get_value_with_default (GKeyFile      *keyfile,
  out:
   return ret;
 }
+
+gboolean
+ot_keyfile_copy_group (GKeyFile   *source_keyfile,
+                       GKeyFile   *target_keyfile,
+                       const char *group_name)
+{
+  gs_strfreev char **keys = NULL;
+  gsize length, ii;
+  gboolean ret = FALSE;
+
+  g_return_if_fail (source_keyfile != NULL);
+  g_return_if_fail (target_keyfile != NULL);
+  g_return_if_fail (group_name != NULL);
+
+  keys = g_key_file_get_keys (source_keyfile, group_name, &length, NULL);
+
+  if (keys == NULL)
+    goto out;
+
+  for (ii = 0; ii < length; ii++)
+    {
+      gs_free char *value = NULL;
+
+      value = g_key_file_get_value (source_keyfile, group_name, keys[ii], NULL);
+      g_key_file_set_value (target_keyfile, group_name, keys[ii], value);
+    }
+
+  ret = TRUE;
+
+ out:
+  return ret;
+}
index 057cc638fe5fe5320a2ce8931814028b86a9f0ed..576785ace535bb9fd444467fc6de54975ab32707 100644 (file)
@@ -43,5 +43,10 @@ ot_keyfile_get_value_with_default (GKeyFile      *keyfile,
                                    char         **out_value,
                                    GError       **error);
 
+gboolean
+ot_keyfile_copy_group (GKeyFile   *source_keyfile,
+                       GKeyFile   *target_keyfile,
+                       const char *group_name);
+
 G_END_DECLS